import java.awt.Color;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Comparator;
/**
 * 
 * @author Adam and Terry 
 *
 */
public class CustomPoint extends Path2D.Double implements Comparator<CustomPoint> {

	private static final long serialVersionUID = 741713763308816772L;
	private String name;
	private double x;
	private double y;
	private Color colour;
	private String delimiter; 

	/**
	 * 
	 * @param name
	 */
	
	public CustomPoint(String name) {
		this.name = "";
		this.colour= Color.BLACK;
	}
	
	/**
	 * 
	 * @param name
	 * @param delimiter
	 */
	public CustomPoint(String name, String delimiter) {
		this.name = "";
		this.delimiter = delimiter; 
		this.colour = Color.PINK;
	}
	
	/**
	 * 
	 * @param name
	 * @param temp
	 */
	
	public CustomPoint(String name, Point2D.Double temp){
		this.name = name; 
		this.x = temp.getX();
		this.y = temp.getY(); 
	}
	
	/**
	 * 
	 */
	public String toString()
	{
		return this.name + "|" + this.x + "|" + this.y + "\n";
	}
	
	/**
	 * 
	 * @param x
	 */
	
	public void setX(double x){
		this.x = x;
	}
	
	/**
	 * 
	 * @param y
	 */
	public void setY(double y){
		this.y =y; 
	}
	
	/**
	 * 
	 * @return name
	 */

	public String getName() {
		return name;
	}
	
	/**
	 * 
	 * @return colour
	 */
	public Color getColour(){
		return this.colour;
	}
	
	/**
	 * Reads AGM data. Stops when line "END" is read.
	 * 
	 * @param input
	 *            open file which has just read the number
	 * @throws IoException
	 *             or subclass if something goes wrong
	 */
	public void read(BufferedReader input, String line) throws IOException {
		
		Point2D.Double current = null;	
		
		// Reads all the coords from the file in order and adds the lines to the shape
		while (!line.equalsIgnoreCase("end")) {
			
			String[] parts = line.split(this.delimiter);
			
			if(parts.length > 1){
				
				name = parts[0];		
				double x = java.lang.Double.parseDouble(parts[1]);
				double y = java.lang.Double.parseDouble(parts[2]);
				current = new Point2D.Double(x, y);
				append(new Line2D.Double(current.x, current.y, current.x, current.y), true);
				line = input.readLine();
			}
		}
		
	}

	
	/*public int compare(Point o1, Point o2) {
		// TODO Auto-generated method stub
		return o1.toString().hashCode() - o2.toString().hashCode();
	}*/

	public int compare(CustomPoint o1, CustomPoint o2) {
		// TODO Auto-generated method stub
		return o1.toString().hashCode() - o2.toString().hashCode();
	}


}
